﻿using Application.AppSrevices;
using Application.Dto;
using Application.IAppSrevices;
using Domain.Entitys;
using EFCore;
using Microsoft.AspNetCore.Mvc;
using System.Data;

namespace UI.Controllers
{
    public class RolesController : Controller
    {

        private readonly IRolesService RolesService;
        private readonly IUserService userService;

        public RolesController(IRolesService RolesService,IUserService userService)
        {
            this.RolesService = RolesService;
            this.userService = userService;
        }

        //8-1
        public IActionResult Index()
        {
            return View();
        }

        //8-2
        public IActionResult Index2()
        {
            return View();
        }
        public IActionResult Index1()
        {
            return View();
        }
        public IActionResult UserAddYM()
        {
            return View();
        }
        private static int uid;
        public IActionResult UserUpdateYM(int id)
        {
            uid = id;
            return View();
        }
       

        public IActionResult RoleAddYM()
        {
            return View();
        }

        public List<Roles> GetRoles(int a, int b)
        {
            return RolesService.GetRoles(a, b);
        }

        public int GetRolesCount()
        {
            return RolesService.GetRolesCount();
        }
        /// <summary>
        ///角色表 添加
        /// </summary>
        /// <param name="roles"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> RolesAdd(RolesDto   rolesDto)
        {
            int zhi = await RolesService.RolesAdd(rolesDto);
            return Json(zhi);
        }
        /// <summary>
        /// 用户表查询数据
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        [HttpGet]
        public List<User> GetUser(int a, int b)
        {
            return RolesService.GetUser(a, b);
        }
        [HttpGet]
        public int GetUserCount()
        {
            return RolesService.GetUserCount();
        }



        [HttpGet]
        public List<Roles> GetRole2()
        {
            return RolesService.GetRole2();
        }

        [HttpPost]
        public int UserAdd(User user)
        {
            return RolesService.UserAdd(user);
        }


        [HttpGet("Roles/GetUser2")]
        public User GetUser2()
        {
            return RolesService.GetUser2(uid);
        }

        [HttpPut("Roles/UserUpdate")]
        public int UserUpdate(User user)
        {
            return RolesService.UserUpdate(user);
        }

        [HttpDelete]
        public int UserDelete(int uid)
        {
            return RolesService.UserDelete(uid);
        }
        public IActionResult RoleUpdateYM(int id)
        {
            roleid = id;
            return View();
        }

        private static int roleid;
        [HttpGet]
        public Roles GetRole()
        {
            return RolesService.GetRole(roleid);
        }
        [HttpDelete]
        public int Delete(int id)
        {
            return RolesService.Delete(id);
        }

        [HttpPost]
        public int Add(int id, int id2)
        {
            return RolesService.Add(id, id2);
        }

        [HttpGet]
        public int[] GetQXById()
        {
            return RolesService.GetQXById(roleid);
        }
        [HttpGet]
        public List<Jurisdiction> GetQX()
        {
            return RolesService.GetQX();
        }
        [HttpGet]
        public List<XQ> GetQX2(string str)
        {
            return RolesService.GetQX2(str);
        }

        public IActionResult HRFill()
        {
            return Json(userService.URFill());
        }

        public IActionResult HRFill1(int a, int b)
        {
            return Json(userService.URFill1(a, b));
        }
        public IActionResult HRCount()
        {
            return Json(userService.URCount());
        }
        [HttpGet("Roles/UserRroesById")]
        public IActionResult UserRroesById(int uid)
        {
            return Json(userService.UserRroesById(uid));
        }
        [HttpPut("Roles/UserRroesUpdate")]
        public IActionResult UserRroesUpdate(UserRoles userRoles)
        {
            return Json(userService.UserRroesUpdate(userRoles));
        }
        public IActionResult UserDesc()
        {
            return Json(userService.UserDesc());
        }
        [HttpPost("Roles/UserRolesAdd")]
        public IActionResult UserRolesAdd(UserRolesAddDto userRolesAddDto)
        {
            return Json(userService.UserRolesAdd(userRolesAddDto));
        }
        [HttpDelete("Roles/RolesDelete")]
        public IActionResult RolesDelete(RoleDeleteDto roleDeleteDto)
        {
            return Json(userService.RolesDelete(roleDeleteDto));
        }

        [HttpPut("Roles/RolesUpdate")]
        public IActionResult RolesUpdate(Roles roles)
        {
            return Json(RolesService.RolesUpdate(roles));
        }
    }
}
